import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.commons.pool.impl.StackObjectPool;
import com.sap.smb.sbo.api.ICompany;

/**
 * Created by IntelliJ IDEA.
 * User: mlv
 * Date: 2013-2-22
 * Time: 17:39:00
 * To change this template use File | Settings | File Templates.
 */
public class SboPool {

    private static ObjectPool<ICompany> pool;
    static{
         PoolableObjectFactory factory
                = new SboPoolFactory();
         pool = new StackObjectPool<ICompany>(factory,3);
    }

    public static ICompany conn() throws Exception {
        return pool.borrowObject();
    }

    public static void release(ICompany obj) throws Exception {
        if (obj != null)
            pool.returnObject(obj);
    }

    public static void main(String[] args) {
         try {
            for (long i = 0; i < 100 ; i++) {
                System.out.println("== " + i + " ==");
                ICompany obj = SboPool.conn();
                System.out.println("Object:" + obj);
                SboPool.release(obj);
                obj = null;
            }
        }
        catch (Exception e) {
                 e.printStackTrace();
        }
    }
}
